import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.StringConverter;

public class AnimalApp extends Application {
    private ComboBox<Animal> comboBox = new ComboBox<>();
    private Text textNamePrice = new Text();

    public static void main(String[] args) { launch(args); }

    @Override
    public void start(Stage primaryStage) throws Exception {

        comboBox.setConverter(new StringConverter<Animal>() {
            @Override
            public String toString(Animal object) {
                return object.getName();
            }

            @Override
            public Animal fromString(String string) {
                return null;
            }
        });

        comboBox.setItems(FXCollections.observableArrayList(new Animal("Dog", 30.12),
                new Animal("Cat", 23.23),
                new Animal("Bird", 15.0)));

        comboBox.valueProperty().addListener((obs, oldVal, newVal) -> {
            String selectionText = "Price of the " + newVal.getName() + " is : " + newVal.getPrice();

            System.out.println(selectionText);
            textNamePrice.setText(selectionText);
        });

        VBox layout = new VBox(10);
        layout.setPadding(new Insets(60, 60, 60, 60));
        layout.getChildren().addAll(comboBox, textNamePrice);

        Scene scene = new Scene(layout, 500, 350);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public class Animal {
        private String name;
        private Double price;

        public Double getPrice() { return price; }

        public String getName() { return name; }

        public Animal(String name, Double price) {
            this.name = name;
            this.price = price;
        }
    }
}